package kr.hyunist.memoappproject.BaseAdapter;

import java.util.*;

import kr.hyunist.memoappproject.*;
import kr.hyunist.memoappproject.DAO.*;
import kr.hyunist.memoappproject.DTO.*;
import android.content.*;
import android.graphics.*;
import android.view.*;
import android.widget.*;

public class MyMemoAppAdapter extends BaseAdapter {
	Context mainCon; // Context는 Activity다.
	ArrayList<MyMemo> arMemo;
	LayoutInflater inflater;
	int layout;
	TextView memoTitle;
	TextView memoContent;
	TextView memoTime;
	RelativeLayout rel;
	MyMemoAppDAO dao;

	public MyMemoAppAdapter(Context context, int mLayout,
			ArrayList<MyMemo> arList) {
		this.mainCon = context;
		arMemo = arList;
		layout = mLayout;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		dao = MyMemoAppDAO.open(context);
	}

	@Override
	public int getCount() {
		return arMemo.size();
	}

	@Override
	public Object getItem(int position) {
		return arMemo.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos = position;
		int[] mBg = { R.drawable.listbg00, R.drawable.listbg01,
				R.drawable.listbg02, R.drawable.listbg03, R.drawable.listbg04 };

		if (convertView == null) {
			convertView = inflater.inflate(layout, parent, false);
		}

		convertView.setBackgroundResource(mBg[pos % mBg.length]);

		memoTitle = (TextView) convertView.findViewById(R.id.memoapptitletv);
		memoTitle.setText(arMemo.get(pos).getTitle());

		memoContent = (TextView) convertView
				.findViewById(R.id.memoappcontenttv);
		memoContent.setText(arMemo.get(pos).getContents());

		memoTime = (TextView) convertView.findViewById(R.id.memoapptimetv);
		memoTime.setText(arMemo.get(pos).getTime());

		return convertView;
	}

}
